//
//  TTDatabaseObject.h
//  Tint
//
//  Created by Kevin Wu on 5/30/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface TTDatabaseObject : NSObject {
    int _pk;
}

@property(nonatomic, assign) int pk;

+ (BOOL)createTable;

/*
 * Insert or update all fields.
 * pk=0: insert
 * pk>0 and not in database: insert
 * pk>0 and in database: update
 */
- (BOOL)save;

/*
 * Insert or update fields specified.
 * pk=0: insert
 * pk>0 and not in database: insert
 * pk>0 and in database: update
 */
- (BOOL)save:(NSString *)fieldString;

/*
 * Delete from database by pk.
 */
- (void)destroy;


/*
 * Check is exist in database or not by pk.
 */
- (BOOL)isExist;


/*
 * Read from database by pk.
 */
- (void)reload;


+ (NSUInteger)count;

+ (BOOL)deleteAllObjects;
+ (BOOL)deleteObjectsWhere:(NSString *)where, ...;

+ (BOOL)updateAllObjectsSet:(NSString *)set;
+ (BOOL)updateObjectsSet:(NSString *)set where:(NSString *)where, ...;

+ (NSArray *)selectAllObjects;
+ (NSArray *)selectObjectsOrderBy:(NSString *)orderBy;
+ (NSArray *)selectObjectsOrderBy:(NSString *)orderBy where:(NSString *)where, ...;

@end
